package org.jeecg.jt808.operate;


import org.jeecg.jt808.JTT808Encoder;
import org.jeecg.jt808.JTT808Message;
import org.jeecg.jt808.Jt808Control.Jt808CentralControlConfig;
import org.jeecg.jt808.modbus.ModbusParams;
import org.jeecg.jt808.processor.JT808MessageGenerator;
import org.jeecg.jt808.processor.MessageType;
import org.jeecg.jt808.vo.Packet;

import static org.jeecg.jt808.util.JT808Util.bytesToHexString;

public class LocationTrackMessageGenerator implements JT808MessageGenerator {


    @Override
    public String generateMessage(JTT808Message message) {
        return "";
    }

    @Override
    public String generateMessage(JTT808Message message, Jt808CentralControlConfig config) {


        message.id = 0x8202;
        message.packetCount = 0;
        message.packetIndex = 0;

        Packet p = Packet.create(6); //  时间间隔 (2 字节) + 有效期 (4 字节)
        p.addShort((short) config.getTimeInterval());
        p.addInt(config.getValidityPeriod());
        message.body = p.getBytes();

        return bytesToHexString(JTT808Encoder.encode(message));
    }

    @Override
    public String generateMessage(JTT808Message message, ModbusParams params) {
        return "";
    }

    @Override
    public String getType() {
        return MessageType.LOCATION_TRACK.name();
    }
}
